package com.spic.business.safetyactivity.controller;

import com.spic.business.safetyactivity.domain.SafetyActivitySign;
import com.spic.business.safetyactivity.service.ISafetyActivitySignService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 安全活动签到人员Controller
 *
 * @author spic
 * @date 2022-06-14
 */
@RestController
@RequestMapping("/sign")
public class SafetyActivitySignController extends BaseController {
    @Autowired
    private ISafetyActivitySignService safetyActivitySignService;

    /**
     * 查询安全活动签到人员列表
     */
    @GetMapping("/list")
    public AjaxResult list(SafetyActivitySign safetyActivitySign) {
        Map<String, List<SafetyActivitySign>> map = safetyActivitySignService.selectSafetyActivitySignList(safetyActivitySign);
        return AjaxResult.success(map);
    }

    /**
     * 导出安全活动签到人员列表
     */
//    @Log(title = "安全活动签到人员", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SafetyActivitySign safetyActivitySign) throws IOException {
//        List<SafetyActivitySign> list = safetyActivitySignService.selectSafetyActivitySignList(safetyActivitySign);
//        ExcelUtil<SafetyActivitySign> util = new ExcelUtil<SafetyActivitySign>(SafetyActivitySign.class);
//        util.exportExcel(response, list, "安全活动签到人员数据");
//    }

    /**
     * 获取安全活动签到人员详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(safetyActivitySignService.selectSafetyActivitySignById(id));
    }

    /**
     * 新增安全活动签到人员
     */
    @Log(title = "安全活动签到人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SafetyActivitySign safetyActivitySign) {
        return toAjax(safetyActivitySignService.insertSafetyActivitySign(safetyActivitySign));
    }

    /**
     * 修改安全活动签到人员
     */
    @Log(title = "安全活动签到人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyActivitySign safetyActivitySign) {
        return toAjax(safetyActivitySignService.updateSafetyActivitySign(safetyActivitySign));
    }

    /**
     * 删除安全活动签到人员
     */
    @Log(title = "安全活动签到人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(safetyActivitySignService.deleteSafetyActivitySignByIds(ids));
    }
}
